#include <Megabrite.h>
#include <MegabriteController.h>
#include <math.h>
#include <avr/pgmspace.h>

#define clockpin 13
#define enablepin 10
#define latchpin 9
#define datapin 11

int count = 0;
int min = 0;
Megabrite megabrites[8];
MegabriteController megabriteController;

void setup() {
	Serial.begin(9600);
	megabriteController.setDataPin(11);;
	megabriteController.setLatchPin(9);
	megabriteController.setEnablePin(10);
	megabriteController.setClockPin(13);
	
	for (int i = 0; i < 8; i++) {
		Serial.println("creating megabrite in loop");
		Megabrite megabrite;
		megabrite.red(min);
		megabrite.green(min);
		megabrite.blue(min);
		megabriteController.addMegabrite(&megabrite);
	}

	megabriteController.init();
}

void loop() {
	int number = megabriteController.numberOfMegabrites();
	for (int i = 0; i < number; i++) {
		Megabrite megabrite = megabrites[i];
		if (i == count) {
			megabrite.blue(1023);
		} else {
			megabrite.blue(0);
		}
	}

	megabriteController.send();
	count++;
	if (count > 7) {
		count = 0;
	}
	delay(500);
}

